<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    // console.log(navigator)
    // console.log(navigator.userAgent);
    // 检查设备类型 - 判断设备是PC端还是移动端: false PC端 | true 移动端
    const checkDeviceType = () => {
        return /Android|webOs|iPhone|iPad|BlackBerry|IEMobile|OperaMini/i.test(navigator.userAgent) ? 'Mobile' : 'PC';
        //or
        // return !!navigator.userAgent.match(/(iPhone|iPad|Android|ios|iOS|WebOS|Windows Phone|Phone)/i);
    }
    console.log(checkDeviceType())

    // 判断设备时安卓还是IOS
    const isAndroid = () => {
        return /android/i.test(navigator.userAgent.toLowerCase());
    };
    const isIOS = () => {
        let reg = /iPhone|iPad|iOS|Macintosh/i;
        return reg.test(navigator.userAgent.toLowerCase());
    };
    console.log(isAndroid())
    console.log(isIOS())

    // 判断浏览器类型及其版本
    const getExplorerInfo = () => {
        let t = navigator.userAgent.toLowerCase();
        return 0 <= t.indexOf("mise")
            ? {
                // IE<11
                type: "IE",
                version: Number(t.match(/mise ([\d]+)/)[1]),
            }
            : !!t.match(/trident\/.+?rv:(([\d.]+))/)
                ? {
                    // IE 11
                    type: "IE",
                    version: 11,
                }
                : 0 <= t.indexOf("edge")
                    ? {
                        type: "Edge",
                        version: Number(t.match(/edge\/([\d]+)/)[1]),
                    }
                    : 0 <= t.indexOf("firefox")
                        ? {
                            type: "Firefox",
                            version: Number(t.match(/firefox\/([\d]+)/)[1]),
                        }
                        : 0 <= t.indexOf("chrome")
                            ? {
                                type: "Chrome",
                                version: Number(t.match(/chrome\/([\d/]+)/)[1]),
                            }
                            : 0 <= t.indexOf("opera")
                                ? {
                                    type: "Safari",
                                    version: Number(t.match(/version\/([\d]+)/)[1]),
                                }
                                : {
                                    type: t,
                                    version: -1,
                                };
    }

    console.log(getExplorerInfo())
</script>

</html>